package com.rocksdata.mc.ui.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.ctz.commonframe.utils.DensityUtil;
import com.ctz.commonframe.utils.GlideApp;

import java.util.List;

/**
 * Created by 陈堂正 on 2017/4/7.
 */

public class NewsImageGridAdapter extends BaseAdapter {
    private Context context;
    private List<String> imageList;

    public NewsImageGridAdapter(Context context, List<String> imageList){
        this.context = context;
        this.imageList = imageList;
    }

    @Override
    public int getCount() {
        return imageList.size() > 2 ? 3 : imageList.size();
    }

    @Override
    public String getItem(int position) {
        return imageList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        String bean = getItem(position);
        if(convertView == null){
            convertView = new ImageView(context);
            convertView.setLayoutParams(new AbsListView.LayoutParams(AbsListView.LayoutParams.MATCH_PARENT, DensityUtil.dip2px(context, 70)));
        }
//        if(Config.isDebug){
//            ((ImageView)convertView).setImageResource(bean.getRes());
//        }else{
//            XUtils3ImageDisplayer.display((ImageView)convertView, bean.getImageUrl());
//        }
        GlideApp.with(context).load(bean).into((ImageView)convertView);
        return convertView;
    }
}
